#include "state_rpgbattle.h"

void CStateRPGBattle::Init()
{

	m_Tag = "StateRPGBattle";

	m_bStarted = true;

}


void CStateRPGBattle::PreRun()
{

	m_iStateMessage = 1;

}

void CStateRPGBattle::Input()
{
	
	SDL_Event ev;
	
	SDL_PollEvent( &ev );
	
	Uint8 * keys = SDL_GetKeyState( NULL );
	
	if( ev.key.keysym.sym == SDLK_ESCAPE )
	{

		m_iStateMessage = 0;
		
	}
	
	if( ev.type == SDL_QUIT )
	{
	
		m_iStateMessage = 0;
		
	}
	

	m_pGameInterface->BattleSystem()->Input( ev, keys );
	

}

void CStateRPGBattle::Think()
{

	m_pGameInterface->BattleSystem()->Think();

	m_pGameInterface->CallEngineHook( "BattleSystemThink" );
	
	if( m_pGameInterface->BattleSystem()->BattleEnding() )
	{
		
		m_pGameInterface->BattleSystem()->CleanBattle();
		m_iStateMessage = STM_GOTO_2DRPG;
		
	}
	
}


void CStateRPGBattle::Draw()
{
	
	if( m_pGameInterface->BattleSystem()->BattleEnding() )
		return;
	
	CLEAR_BUFFER;
	
	m_pGameInterface->BattleSystem()->DrawBackground();
	m_pGameInterface->BattleSystem()->DrawEntities();
	m_pGameInterface->BattleSystem()->DrawHUD();
	
	m_pGameInterface->CallEngineHook( "PreBlackBarRPGBattleDraw" );
	
	Draw::DisableTextures();
	
	Draw::Color4f( 0.0f, 0.0f, 0.0f, 1.0f );
	Draw::Quad( 0.0f, 0.0f, 0.0f, SCREEN_WIDTH, BATTLETRANSITION_HEIGHT );
	Draw::Quad( 0.0f, SCREEN_HEIGHT - BATTLETRANSITION_HEIGHT, 0.0f, SCREEN_WIDTH, BATTLETRANSITION_HEIGHT );
	
	Draw::EnableTextures();
	
	m_pGameInterface->CallEngineHook( "PostRPGBattleDraw" );
	
	SWAP_BUFFERS;

}






